home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / utils / xad / developer / sources / clients / superduper3.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  4KB  |  151 lines

  1. #ifndef XADMASTER_SUPERDUPER3_C
  2. #define XADMASTER_SUPERDUPER3_C
  3.  
  4. /* Programmheader
  5.  
  6.     Name:        SuperDuper3.c
  7.     Main:        xadmaster
  8.     Versionstring:    $VER: SuperDuper3.c 1.0 (07.09.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    SuperDuper3 disk image client
  12.  
  13.  1.0   07.09.98 : first version
  14. */
  15.  
  16. #include <proto/xadmaster.h>
  17. #include <exec/memory.h>
  18. #include "SDI_compiler.h"
  19. #include "xpkstuff.c"
  20.  
  21. #ifndef XADMASTERFILE
  22. #define SuperDuper3_Client    FirstClient
  23. #define NEXTCLIENT        0
  24. UBYTE version[] = "$VER: SuperDuper3 1.0 (07.09.1998)";
  25. #endif
  26. #define SUPERDUPER3_VERSION    1
  27. #define SUPERDUPER3_REVISION    0
  28.  
  29. ASM(BOOL) SuperDuper3_RecogData(REG(d0, ULONG size), REG(a0, STRPTR data),
  30. REG(a6, struct xadMasterBase *xadMasterBase))
  31. {
  32.   if(((ULONG *) data)[0] == 0x464F524D &&
  33.   (((ULONG *) data)[2] == 0x53444444 ||
  34.   ((ULONG *) data)[2] == 0x53444844))
  35.     return 1;
  36.   else
  37.     return 0;
  38. }
  39.  
  40. ASM(LONG) SuperDuper3_GetInfo(REG(a0, struct xadArchiveInfo *ai),
  41. REG(a6, struct xadMasterBase *xadMasterBase))
  42. {
  43.   LONG err;
  44.   ULONG dat[9], num = 0;
  45.   struct xadDiskInfo *xdi;
  46.  
  47.   if(!(xdi = (struct xadDiskInfo *) xadAllocObjectA(XADOBJ_DISKINFO, 0)))
  48.     return XADERR_NOMEMORY;
  49.   ai->xai_DiskInfo = xdi;
  50.  
  51.   if((err = xadHookAccess(XADAC_READ, 12, dat, ai)))
  52.     return err;
  53.  
  54.   xdi->xdi_EntryNumber = 1;
  55.   xdi->xdi_SectorSize = 512;
  56.   xdi->xdi_Cylinders = 80;
  57.   xdi->xdi_Heads = 2;
  58.   xdi->xdi_Flags = XADDIF_GUESSLOWCYL|XADDIF_GUESSHIGHCYL;
  59. /*xdi->xdi_LowCyl = 0; */
  60.   xdi->xdi_TrackSectors = dat[2] == 0x53444844 ? 22 : 11;
  61.   xdi->xdi_CylSectors = 2 * xdi->xdi_TrackSectors;
  62.   xdi->xdi_TotalSectors = 80 * xdi->xdi_CylSectors;
  63.  
  64.   while(ai->xai_InPos < ai->xai_InSize)
  65.   {
  66.     if((err = xadHookAccess(XADAC_READ, 36, dat, ai)))
  67.       return err;
  68.     if((err = xadHookAccess(XADAC_INPUTSEEK, dat[1]-28, 0, ai)))
  69.       return err;
  70.     ++num;
  71.     if(dat[0] == 0x58504B46 && (dat[8] & (1<<25)))
  72.     { /* check for password flag in every entry */
  73.       ai->xai_Flags |= XADAIF_CRYPTED;
  74.       xdi->xdi_Flags |= XADDIF_CRYPTED;
  75.     }
  76.   }
  77.   if((err = xadHookAccess(XADAC_INPUTSEEK, 12 - ai->xai_InPos, 0, ai)))
  78.     return err;
  79.  
  80.   if(num > 80)
  81.     return XADERR_ILLEGALDATA;
  82.  
  83.   xdi->xdi_HighCyl = num-1;
  84.  
  85.   return 0;
  86. }
  87.  
  88. ASM(LONG) SuperDuper3_UnArchive(REG(a0, struct xadArchiveInfo *ai),
  89. REG(a6, struct xadMasterBase *xadMasterBase))
  90. {
  91.   LONG i, err = 0, u;
  92.   struct {
  93.     STRPTR a;
  94.     ULONG  s;
  95.   } dat;
  96.   struct ExecBase * SysBase = xadMasterBase->xmb_SysBase;
  97.  
  98.   u = ai->xai_InPos;
  99.  
  100.   /* skip entries */
  101.   for(i = ai->xai_CurDisk->xdi_LowCyl; !err && i < ai->xai_LowCyl; ++i)
  102.   {
  103.     if(!(err = xadHookAccess(XADAC_READ, 8, &dat, ai)))
  104.       err = xadHookAccess(XADAC_INPUTSEEK, dat.s, 0, ai);
  105.   }
  106.  
  107.   for(; !err && i <= ai->xai_HighCyl; ++i)
  108.   {
  109.     if(!(err = xadHookAccess(XADAC_READ, 8, &dat, ai)))
  110.     {
  111.       if(dat.a == (STRPTR) 0x58504B46)
  112.       {
  113.         if(!(err = xadHookAccess(XADAC_INPUTSEEK, -8, 0, ai)))
  114.         {
  115.           if(!(err = xpkDecrunch(&dat.a, &dat.s, ai, xadMasterBase)))
  116.           {
  117.             err = xadHookAccess(XADAC_WRITE, dat.s, dat.a, ai);
  118.             FreeVec(dat.a);
  119.           }
  120.         }
  121.       }
  122.       else /* normal BODY chunk */
  123.         err = xadHookAccess(XADAC_COPY, dat.s, 0, ai);
  124.     }
  125.   }
  126.  
  127.   /* seek back to start */
  128.   if(!err)
  129.     err = xadHookAccess(XADAC_INPUTSEEK, u-ai->xai_InPos, 0, ai);
  130.  
  131.   return err;
  132. }
  133.  
  134. ASM(void) SuperDuper3_Free(REG(a0, struct xadArchiveInfo *ai),
  135. REG(a6, struct xadMasterBase *xadMasterBase))
  136. {
  137.   if(ai->xai_DiskInfo)
  138.   {
  139.     xadFreeObjectA(ai->xai_DiskInfo, 0);
  140.     ai->xai_DiskInfo = 0; /* clear the entry */
  141.   }
  142. }
  143.  
  144. struct xadClient SuperDuper3_Client = {
  145. NEXTCLIENT, XADCLIENT_VERSION, 1, SUPERDUPER3_VERSION, SUPERDUPER3_REVISION,
  146. 12, XADCF_DISKARCHIVER, XADCID_SUPERDUPER3, "SuperDuper3",
  147. (BOOL (*)()) SuperDuper3_RecogData, (LONG (*)()) SuperDuper3_GetInfo,
  148. (LONG (*)()) SuperDuper3_UnArchive, (void (*)()) SuperDuper3_Free};
  149.  
  150. #endif /* XADASTER_SUPERDUPER3_C */
  151.